package com.encryption.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.encryption.dao.Condition;
import com.encryption.dao.FileLogDAO;
import com.encryption.model.FileLog;
import com.encryption.service.OperationLogService;
/**
 * 文件操作日志服务接口实现类
 * @author Administrator
 *
 */
public class OperationLogServiceImpl implements OperationLogService {
	
	private static final Logger log = LoggerFactory.getLogger(OperationLogServiceImpl.class);
	
	private static OperationLogServiceImpl operationLogServiceImpl = null;
	
	
	public static  OperationLogServiceImpl getOperationLogServiceImpl(){
		if(null == operationLogServiceImpl) {
			operationLogServiceImpl = new OperationLogServiceImpl();
		} 
		return operationLogServiceImpl;
	}
	/**
	 * 添加操作日志
	 * @param  
	 */
	public boolean addLog(FileLog fileLog){
		try {
			FileLogDAO.getFileLogDAO().save(fileLog);
		} catch (Exception e) {
			log.error("add log error:",e);
			return false;
		}
		return true;
	}
	
	/**
	 * 根据用户ID获取所有的操作记录
	 * @param userId
	 * @return
	 */
	public List<FileLog> getByUserId(int userId){
		return FileLogDAO.getFileLogDAO().findByProperty("user",userId);
	}
	
	/**
	 * 根据文件ID获取所有操纵记录
	 * @param fileId
	 * @return
	 */
	public List<FileLog> getByFileId(int fileId){
		return FileLogDAO.getFileLogDAO().findByProperty("file",fileId);
	}
	
	/**
	 * 根据条件获取所有的操作记录
	 * @param condList
	 * @return
	 */
	public List<FileLog> getByCondition(List<Condition> condList){
		return FileLogDAO.getFileLogDAO().findByExample(condList);
	}
	
	/**
	 * 根据条件分页获取所有的操作记录
	 * @param condList
	 * @param page
	 * @param pageSize
	 * @return
	 */
	public List<FileLog> getPagingByCondition(List<Condition> condList,int page,int pageSize){
		return FileLogDAO.getFileLogDAO().findByExample4Page(condList, page, pageSize);
	}
	

}
